/*!***************************************************
 * @file: app.h
 * @brief: 程序的总调度层
 * @author: ITHAO 
 * @date: 2018.11.19
 * @note: 
 ****************************************************/
#include <setjmp.h>
#include <pthread.h>

#include "comm_protocol_core.h"
#include "login_app.h"
#include "list.h"
#include "interface.h"


#ifndef __APP_H__
#define __APP_H__

enum {
    APP_PARAM_NULL = 1,
    APP_CREATE_PTHREAD_ERR,
};

/*这里这里通信fd要做互斥，不然接受线程会抢占接受，
如果有函数要通信，就传入这个结构体，通信时做互斥*/
struct mutexfd {
    int clientfd;
    pthread_mutex_t mutex;
};

struct app {
    struct mutexfd mutexfd;/*带互斥的socketfd*/
    struct login_info user_login_info;/*用户账号信息*/
    struct list_head friend_list_head;/*好友表*/
    pthread_t recv_thread;/*接受线程*/
    struct interface *p_interface;
};


extern int init(struct app *p_app);
extern int run(struct app *p_app);
extern int destroy(struct app *p_app);

#endif